using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
namespace RefCheckRewrite
{
  [Serializable]
  class FrmFileTime:Form
  {
    string format="yyyy-MM-dd HH:mm:ss";
    FileInfo file=null;
    TextBox txtLWDate,txtLADate,txtCRDate;
    Button btnSave;
    public FrmFileTime(FileInfo filename)
    {
      this.StartPosition=FormStartPosition.CenterParent;
      this.Text=filename.Name;
      this.Padding=new Padding(20);
      this.AutoSize=true;
      this.AutoSizeMode=AutoSizeMode.GrowAndShrink;
      this.MaximizeBox=false;
      this.MinimizeBox=false;
      this.FormBorderStyle=FormBorderStyle.FixedDialog;
      this.TopMost=true;
      int margin=9;
      txtCRDate=new TextBox();
      txtCRDate.Left=margin;
      txtCRDate.Top=margin*2;
      txtCRDate.Width=300;
      this.Controls.Add(txtCRDate);
      txtLWDate=new TextBox();
      txtLWDate.Left=margin;
      txtLWDate.Top=margin*5;
      txtLWDate.Width=300;
      this.Controls.Add(txtLWDate);
      txtLADate=new TextBox();
      txtLADate.Left=margin;
      txtLADate.Top=margin*8;
      txtLADate.Width=300;
      this.Controls.Add(txtLADate);
      btnSave=new Button();
      btnSave.Left=margin+txtLWDate.Width+5; ;
      btnSave.Top=txtCRDate.Top;
      btnSave.Text="&Save";
      btnSave.Height=75;
      btnSave.Enabled=false;
      btnSave.Click+=new EventHandler(btnSave_Click);
      this.Controls.Add(btnSave);
      txtLWDate.TextChanged-=txtDateChanged;
      txtLADate.TextChanged-=txtDateChanged;
      txtCRDate.TextChanged-=txtDateChanged;
      this.file=filename;
      txtLWDate.Text=file.LastWriteTime.ToString(format);
      txtLADate.Text=file.LastAccessTime.ToString(format);
      txtCRDate.Text=file.CreationTime.ToString(format);
      txtLWDate.TextChanged+=txtDateChanged;
      txtLADate.TextChanged+=txtDateChanged;
      txtCRDate.TextChanged+=txtDateChanged;
    }
    void txtDateChanged(object sender,EventArgs e)
    {
      TextBox txb=sender as TextBox;
      if(txb!=null)
      {
        DateTime temp;
        btnSave.Enabled=DateTime.TryParseExact(txb.Text,format,null,System.Globalization.DateTimeStyles.None,out temp);
      }
    }
    void btnSave_Click(object sender,EventArgs e)
    {
      file.LastAccessTime=DateTime.ParseExact(txtLADate.Text.Trim(),format,null);
      file.LastWriteTime=DateTime.ParseExact(txtLWDate.Text.Trim(),format,null);
      file.CreationTime=DateTime.ParseExact(txtCRDate.Text.Trim(),format,null);
      btnSave.Enabled=false;
    }
  }
}
